package com.gnerv.sylvanas.business.manage.controller;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.business.manage.logic.OrgLogicService;
import com.gnerv.sylvanas.business.manage.model.dto.OrgAccountDTO;
import com.gnerv.sylvanas.business.manage.model.dto.OrgCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.OrgDTO;
import com.gnerv.sylvanas.business.manage.model.dto.OrgTreeDTO;
import com.gnerv.sylvanas.business.manage.model.dto.OrgUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/api/manage/org")
public class OrgController {

    private final OrgLogicService orgLogicService;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody OrgCreateDTO orgCreateDTO) {
        return orgLogicService.create(orgCreateDTO);
    }

    @PutMapping(value = "/bind/account")
    public RestResult<Void> bindAccount(@RequestBody OrgAccountDTO orgAccountDTO) {
        return orgLogicService.bindAccount(orgAccountDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return orgLogicService.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody OrgUpdateDTO orgUpdateDTO) {
        return orgLogicService.updateByUkId(orgUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<OrgDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return orgLogicService.selectByUkId(ukId);
    }

    @GetMapping(value = "/list")
    public RestResult<List<OrgDTO>> selectListByName(@RequestParam(required = false, name = "name") String name) {
        return orgLogicService.selectListByName(name);
    }

    @GetMapping(value = "/list/parent")
    public RestResult<List<OrgDTO>> selectListByParentUkId(@RequestParam(value = "parentUkId") String parentUkId) {
        return orgLogicService.selectListByParentUkId(parentUkId);
    }

    @GetMapping(value = "/list/tree")
    public RestResult<List<OrgTreeDTO>> selectListTreeByParentUkId(@RequestParam(value = "parentUkId") String parentUkId) {
        return orgLogicService.selectListTreeByParentUkId(parentUkId);
    }

}
